home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6487 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  46 lines

  1. Path: darkstar.UCSC.EDU!kama!jono
  2. From: jono@cse.ucsc.edu (Jonathan Gibbs)
  3. Newsgroups: comp.lang.c++
  4. Subject: Templates & protected
  5. Date: 8 Feb 1996 22:15:42 GMT
  6. Organization: UC Santa Cruz CIS/CE
  7. Message-ID: <4fdsme$9ba@darkstar.UCSC.EDU>
  8. NNTP-Posting-Host: kama.cse.ucsc.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I know the if class B is derived from class A, then B can see A's 
  12. protected members, but what if B and A are templated as follows:
  13.  
  14. template <int T>
  15. class A
  16. {...};
  17.  
  18. template <int U>
  19. class B : public A<2>
  20. {...};
  21.  
  22. I assume all B's can see A<2>'s protected members, but can it see
  23. A<3>'s? g++ says not. Is there any way around this?
  24.  
  25. Real Sample code & error:
  26.  
  27. template <class TYPE, int SIZE>
  28. class Vector {...
  29.  
  30. template <class TYPE, int ROWS, int COLS>
  31. class Matrix : public Vector<TYPE, ROWS*COLS> {...
  32.  
  33. Error:
  34. matrix.h: 
  35.    In method `class Matrix<float,3,3> 
  36.           Matrix<float,3,3>::tilde(class Vector<float,3> &)':
  37.    146: member `_data' is a protected member of class `Vector<float,3>'
  38.  
  39. HELP!
  40.  
  41. --
  42. "The human mind is a dangerous plaything, boys. When it's used for evil, 
  43. watch out! But when it's used for good, then things are much nicer." 
  44.                                                             -- The Tick
  45. <Home Page: http://www.cse.ucsc.edu/~jono>
  46.